local sk__hanyong = fk.CreateSkill {

  name = "sk__hanyong",

  tags = { Skill.Compulsory, },

}



sk__hanyong:addEffect(fk.CardEffectCancelledOut, {
  name = "sk__hanyong",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(sk__hanyong.name) then
      return player:getEquipment(Card.SubtypeWeapon) == nil and
          #player:getAvailableEquipSlots(Card.SubtypeWeapon) > 0 and data.from == player
          and data.card.trueName == "slash" and not data.to.dead
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cards = {}
    for _, id in ipairs(player:getCardIds("he")) do
      if not player:prohibitDiscard(id) and
          not (table.contains(player:getEquipments(Card.SubtypeWeapon), id) and Fk:getCardById(id).name == "axe") then
        table.insert(cards, id)
      end
    end
    cards = room:askToDiscard(player, {
      min_num = 2,
      max_num = 2,
      include_equip = true,
      skill_name = sk__hanyong.name,
      cancelable = true,
      pattern = tostring(Exppattern { id = cards }),
      prompt = "#axe-invoke::" .. data.to.id,
      skip = true
    })
    if #cards > 0 then
      event:setCostData(self, { cards = cards })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:throwCard(event:getCostData(self).cards, skill.name, player, player)
    data.isCancellOut = false
  end,
})
sk__hanyong:addEffect(fk.PreCardEffect, {
  name = "sk__hanyong",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(sk__hanyong.name) then
      if player:getEquipment(Card.SubtypeArmor) == nil and
          #player:getAvailableEquipSlots(Card.SubtypeArmor) > 0 and
          player:getMark(MarkEnum.MarkArmorNullified) == 0 then
        return player == data.to and table.contains({ "slash", "savage_assault", "archery_attack" }, data.card.name)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:broadcastPlaySound("./packages/maneuvering/audio/card/vine")
    room:setEmotion(player, "./packages/maneuvering/image/anim/vine")
    data.nullified = true
  end,
})
sk__hanyong:addEffect(fk.DamageInflicted, {
  name = "sk__hanyong",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(sk__hanyong.name) then
      if player:getEquipment(Card.SubtypeArmor) == nil and
          #player:getAvailableEquipSlots(Card.SubtypeArmor) > 0 and
          player:getMark(MarkEnum.MarkArmorNullified) == 0 then
        return target == player and data.damageType == fk.FireDamage
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke(sk__hanyong.name)
    local room = player.room
    room:broadcastPlaySound("./packages/maneuvering/audio/card/vineburn")
    room:setEmotion(player, "./packages/maneuvering/image/anim/vineburn")
    data:changeDamage(1)
  end,
})

sk__hanyong:addEffect("atkrange", {
  name = "#sk__hanyong_attackrange",
  fixed_func = function(self, from)
    if from:hasSkill("sk__hanyong") and from:getEquipment(Card.SubtypeWeapon) == nil and
        #from:getAvailableEquipSlots(Card.SubtypeWeapon) > 0 then
      return 3
    end
  end,
})

return sk__hanyong
